package org.jinyan.quartz.example.scheduler;

import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;

public class Example01 {

	public void run() throws ClassNotFoundException, InterruptedException {
		System.err.println("start");
		SchedulerFactory sf = new StdSchedulerFactory();
		Class jobClass = Class
				.forName("org.jinyan.quartz.example.job.HelloJob");

		JobDetail job = JobBuilder.newJob(jobClass)
				.withIdentity(new JobKey("testHello", "testGroup01")).build();
		Date triggerStartTime = new Date();
		Trigger trigger = TriggerBuilder
				.newTrigger()
				.withIdentity(new TriggerKey("testTrigger", "testGroup01"))
				.startNow()
				.withSchedule(
						SimpleScheduleBuilder.simpleSchedule()
								.withIntervalInSeconds(10).withRepeatCount(10))
				.build();
		Scheduler scheduler = null;
		try {
			scheduler = sf.getScheduler();
			scheduler.scheduleJob(job, trigger);
			scheduler.start();
			
			scheduler.pauseTrigger(new TriggerKey("testTrigger", "testGroup01"));
			Thread.sleep(10000L);
			scheduler.rescheduleJob(new TriggerKey("testTrigger", "testGroup01"), trigger);
			// scheduler.shutdown();
		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.err.println("over");
	}

	public static void main(String[] args) throws ClassNotFoundException, InterruptedException {

		new Example01().run();

	}
}
